package com.mz.ozy.mvp.presenter;


import android.app.Activity;


import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.mvp.model.ForgetPwdModel;
import com.mz.ozy.mvp.view.ForgetPwdContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class ForgetPwdPresenter extends BasePresenterImpl<ForgetPwdContract.View> implements ForgetPwdContract.Presenter {

    private ForgetPwdModel mForgetPwdModel;

    public ForgetPwdPresenter() {
        mForgetPwdModel = new ForgetPwdModel();
    }

    @Override
    public void obtainForgetPwd(Activity activity, String user,String userName, String code, String password) {
        mForgetPwdModel.onForgetPwd(activity, user,userName, code, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.obtainForgetPwdSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void getCode(Activity activity, String username, String user) {
        mForgetPwdModel.getCode(activity, username,user)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.getCodeSuccess(jsonObject);
                    }

                });
    }
}
